<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="static/css/bootstrap.min.css">
</head>


<body>
    <!-- 给一个容器 -->
    <div class="container">
        <div class="row text-center">
            <h1>学生信息管理系统</h1>
            <hr>

            <a href="" class="btn btn-success">首页</a>
            <a href="add.html" class="btn btn-warning">添加</a>

            <br>
            <br>
        </div>


        <div class="row">

            <table id="tb" class="table table-bordered table-condensed table-hover table-responsive text-center">
                <tbody>
                    <tr>
                        <th>ID</th>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>年龄</th>
                        <th>qq</th>
                    </tr>
                    <!-- 将result的数据遍历出来 -->
                    <!-- <tr>
                        <td>1</td>
                        <td>2</td>
                        <td>3</td>
                        <td>4</td>
                     </tr> -->
                </tbody>
            </table>
        </div>
    </div>

</body>

</html>
<script src="./static/js/jquery.min.js"></script>
<script>
    let tb = document.getElementById("tb");
    let xhr = new XMLHttpRequest();
    xhr.open("get", "/index", true);
    xhr.send();
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && xhr.status == 200) {
            let str = "";
            let data = JSON.parse(xhr.response).data;
            data.forEach(v =>
                str += `<tr>
                        <td>${v.id}</td>
                        <td>${v.name}</td>
                        <td>${v.sex}</td>
                        <td>${v.age}</td>
                        <td>${v.qq}</td></tr>
                     `
            );
            tb.innerHTML = ` <tr>
                    <th>ID</th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>年龄</th>
                    <th>qq</th>
                </tr>` + str
        } else {
            console.log('查询失败');
        }
    }
</script>